import pickle as pkl
import joblib
import numpy as np
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
pos_feat_file = open('./Data/Processed/pos_feat.pkl','rb')
pos_custom_id = pkl.load(pos_feat_file)
pos_FN = pkl.load(pos_feat_file)
pos_Active = pkl.load(pos_feat_file)
pos_club_member_status = pkl.load(pos_feat_file)
pos_fashion_news_frequency = pkl.load(pos_feat_file)
pos_age = pkl.load(pos_feat_file)
pos_artid = pkl.load(pos_feat_file)
pos_pcode = pkl.load(pos_feat_file)
pos_sales_channel_id = pkl.load(pos_feat_file)
pos_isval = pkl.load(pos_feat_file)

testrange = [i for i in range(len(pos_isval)) if pos_isval[i] == 0]
testrange = np.array(testrange)
print('testrange ok')
valrange = [i for i in range(len(pos_isval)) if pos_isval[i] == 1]
valrange = np.array(valrange)
print('valrange ok')
shape = [(i+1)*1000000 for i in range(30)]
shape.append(len(testrange))
divide_testrange = np.split(testrange,shape)
pos_artid_seq_file = open('./Data/Processed/pos_artid_seq.pkl','rb')
pos_artid_seq = pkl.load(pos_artid_seq_file)
for i in range(31):
    pos_artid_seq_divide = np.array([pos_artid_seq[j] for j in divide_testrange[i]])
    f=open(f'./Data/Processed/divide/pos_artid_seq{i}.db','wb')
    joblib.dump(pos_artid_seq_divide,f)
    f.close()
    pos_artid_seq_divide = None
pos_artid_seq_val = np.array([pos_artid_seq[i] for i in valrange])
f = open(f'./Data/Processed/divide/pos_artid_seq_val.db','wb')
joblib.dump(pos_artid_seq_val,f)
f.close()
pos_artid_seq_val = None
pos_pcode_seq_divide_file = None
pos_pcode_seq_val_file = None
pos_feat_divide_file = None
pos_feat_val_file = None